package com.mega.ycy;

import com.chaoswither.chaoswither;
import com.chaoswither.command.ConfigCommand;
import com.chaoswither.entity.EntityChaosWither;
import com.chaoswither.event.DetermineEvent;
import com.realTerminal.realTerminalMod.entity.RealTerminalEntity;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStackLoader;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.Loader;

import java.util.Iterator;
import java.util.List;
import java.util.Objects;

public class Decide {
    public static boolean isWitherWorld(World world) {
        if (!Loader.isModLoaded("chaoswither")) return false;
        return $isWitherWorld(world);
    }

    public static void removeChaosWither() {
        if (!Loader.isModLoaded("chaoswither")) return;
        ItemStackLoader.NOITEM = false;
        DetermineEvent.WITHERLIVE = false;
        ConfigCommand.happymode = false;
    }

    public static boolean $isWitherWorld(World world) {
        if (world == null) {
            return false;
        } else if (!ConfigCommand.happymode) {
            return false;
        } else if (DetermineEvent.getChaosWorld(world)) {
            if (!ItemStackLoader.NOITEM) {
                ItemStackLoader.NOITEM = true;
            }

            return true;
        } else if (DetermineEvent.WITHERLIVE) {
            return true;
        } else if (chaoswither.happymode) {
            return true;
        } else {
            List<Entity> list = world.loadedEntityList;
            if (list != null && !list.isEmpty()) {
                for(int i1 = 0; i1 < list.size(); ++i1) {
                    Entity entity = (Entity)list.get(i1);
                    if (entity != null && entity instanceof EntityChaosWither && !entity.isDead) {
                        return true;
                    }
                }
            }

            return false;
        }
    }

    public static boolean isGodEntityInWorld(World world) {
        if (!Loader.isModLoaded("realterminalmod"))
            return false;
        Iterator<Entity> var1 = world.loadedEntityList.iterator();

        Entity entity;
        do {
            if (!var1.hasNext()) {
                return false;
            }

            entity = (Entity)var1.next();
            if (entity.getClass().equals(RealTerminalEntity.class) && Yiciyuan_EVENT.isDeath(entity))
                return false;
        } while(!entity.getClass().equals(RealTerminalEntity.class));
        return true;
    }
}
